﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PercolationTree.Model;

namespace PercolationTree.Util
{
    class Statistics
    {
        public static bool isTreePassSignal(Tree tree)
        {
            Layer layer = tree.Layers.Last();
            foreach(Node node in layer.Nodes)
                if (node.Type == NodeType.Valid)
                    return true;
            return false;
        }

        public static int getNodesNumber(Tree tree)
        {
            int count = 0;
            foreach (Layer layer in tree.Layers)
            {
                foreach (Node node in layer.Nodes)
                    count++;
            }
            return count;
        }

        public static int getValidNodesNumber(Tree tree)
        {
            int count = 0;
            foreach (Layer layer in tree.Layers)
            {
                foreach (Node node in layer.Nodes)
                    if (node.Type == NodeType.Valid)
                        count++;
            }
            return count;
        }

        public static int getInvalidNodesNumber(Tree tree)
        {
            int count = 0;
            foreach (Layer layer in tree.Layers)
            {
                foreach (Node node in layer.Nodes)
                    if (node.Type == NodeType.Invalid)
                        count++;
            }
            return count;
        }

        public static double getPercentInvalidNodes(Tree tree)
        {
            return (double) getInvalidNodesNumber(tree) / getNodesNumber(tree);
        }

    }
}
